import React from "react";
import type { CSSProperties } from "react";

export type SelectOption = {
  value: string | number;
  label: string;
  disabled?: boolean;
  // label右侧的自定义icon
  icon?: React.ReactNode;
};

export type SelectOptions = Array<SelectOption>;

type BaseProps = {
  options: SelectOptions;
  invalid?: boolean;
  placeholder?: string;
  disabled?: boolean;
  style?: CSSProperties;
  className?: string;
  search?: boolean;
  allowClear?: boolean;
  dropdownRender?: (originNode: React.ReactNode) => React.ReactNode;
  notFoundContent?: React.ReactNode;
};

type Single<V> = BaseProps & {
  value?: V;
  multiple?: false;
  onChange?(value: V): void;
  // onInputChange 输入文字时会提供两个参数是，当前文字和当前所选值
  onInputChange?: (text: string, value: V) => void;
};

type Multi<V> = BaseProps & {
  value?: Array<V>;
  multiple: true;
  allowClearAll?: boolean;
  allowSelectAll?: boolean;
  onChange?(values: Array<V>): void;
  onInputChange?: (text: string, values: Array<V>) => void;
  disabledValueOptions?: Array<{ value: string | number; label: string }>;
};

export type SelectProps<V = string | number> = Single<V> | Multi<V>;
